home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 6
/
The Arsenal Files 6 (Arsenal Computer).ISO
/
prg_casm
/
struc.zip
/
STRUC-C.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-02
|
2KB
|
78 lines
// This code is best compiled using:
// bcc32 -WX -B -3 filename filename.asm
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
// define a structure of various size elements.
struct mystruct{
char c;
unsigned char uc;
short s;
unsigned short us;
long l;
unsigned long ul;
char string [200];
} struct_out;
// This will be a simple function for preformatting our screen.
void format();
// The assembler routine must be declared as "extern" and I'll use the
// "C" type calling convention, since I concider it much easier to not
// have to fiddle with the leading underscores in code of this type.
extern "C" void fill_struct (mystruct *);
main()
{
format();
// Declare a pointer of a type to match my C++ structure
mystruct * struct_ptr;
// And assign the address of the copy of this structure that I'll be dealing
// with here.
struct_ptr = &struct_out;
// Now I'm going to call the assembler function, passing it a pointer to the
// structure within this module.
fill_struct (struct_ptr);
// These are the screen printing routines. They look a bit sloppy here,
// but I wasn't sure how to keep this source any more tidy, and still
// deal with line wrap when others view this code.
cout << "The values below are those passed to the \"C\" structure\n"
"from within the assembler routine.\n\n";
cout << "char : " << (int)struct_out.c << " to "
<< -((int)struct_out.c) << " ascii character ' ~ '" << endl
<< "unsigned char : " << (int)struct_out.uc << endl
<< "short : " << struct_out.s << " to "
<< -struct_out.s << endl
<< "unsigned short: " << struct_out.us << endl
<< "long : " << struct_out.l << " to " << -struct_out.l
<< endl
<< "unsigned long : " << struct_out.ul << endl;
cout << struct_out.string;
getch ();
clrscr();
return 0;
}
void format()
{
clrscr();
for(int a = 0; a < 10; a++) cout << endl;
}